package ar.edu.unicen.pladema.vc1.practico2;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;

import ar.edu.unicen.pladema.ui.model.EjeCoordenadas;
import ar.edu.unicen.pladema.ui.model.PointManager;
import ar.edu.unicen.pladema.ui.model.points.AxisPoint;
import ar.edu.unicen.pladema.ui.model.points.ScreenPoint;
import ar.edu.unicen.pladema.vc1.model.GraphicAttributes;

public class P2Enunciado1Drawer implements PaintListener {
	private EjeCoordenadas ejeCoordenadas;
	private PointManager pointManager;
	private GraphicAttributes graphicAttributes; 

	public P2Enunciado1Drawer(GraphicAttributes ga) {
		this.graphicAttributes = ga;
		ejeCoordenadas = new EjeCoordenadas();
		pointManager = new PointManager();
	}

	@Override
	public void paintControl(PaintEvent e) {
		graphicAttributes
			.add(GraphicAttributes.SIZE_WIDTH, e.width)
			.add(GraphicAttributes.SIZE_HEIGHT, e.height);
		ejeCoordenadas.setScala(
				graphicAttributes.getInt(GraphicAttributes.CLIENT_WIDTH), 
				graphicAttributes.getInt(GraphicAttributes.CLIENT_HEIGHT));

		ejeCoordenadas.setSize(e.width, e.height);
		ejeCoordenadas.drawAxis(e.gc);
		ejeCoordenadas.drawPoints(e.gc, pointManager);
	}
	public int getBoundHeight() {
		return ejeCoordenadas.getScalaY();
	}
	public int getBoundWidth() {
		return ejeCoordenadas.getScalaX();
	}
	public void movePoint(ScreenPoint from, ScreenPoint to) {
		AxisPoint fromAP = ejeCoordenadas.convertPoint(from);
		AxisPoint toAP = ejeCoordenadas.convertPoint(to);
		pointManager.move(fromAP, toAP);
	}
	public PointManager getPointManager() {
		return pointManager;
	}

}
